import axios from 'axios'

const baseURL = 'http://gjt.dormitory.cn',
      timeout = 6000
axios.defaults.withCredentials = true
const instance = axios.create({
  baseURL,
  timeout,

})
instance.interceptors.response.use(response => {
  return response
}, error => {
  let { status } = error.response

  switch (status) {
    case 404:
    {
      /*根据后台返回 状态 进行具体提示 */
      // this.$notify.error({
      //   title: '错误',
      //   message: '这是一条错误的提示消息',
      // })
      break
    }
  }
  return Promise.reject(error)
})
instance.interceptors.request.use( config => {
  // 携带token等等
  config.headers = {
    // 'Authorization':'Bearer '+store.state.Token ,
    'X-Requested-With': 'XMLHttpRequest',
    'Content-Type': 'application/json',
  }
  console.log(config)
  return config

}, err => {
  console.log(err)
  return Promise.reject(err)
})

export function getax(config) {
  return instance(config)
}

export function postax(url, data = {}) {
  return instance.post(url, data)
}

export function putax(url, data = {}) {
  return instance.put(url, data)
}